package nu.aop.service;

import java.util.List;

import nu.aop.model.GroupHitsVO;
import nu.aop.model.StatisticDao;
import nu.aop.model.StatisticPointVO;
import nu.member.model.MemberVO;

public class StatisticServiceImpl implements StatisticService{
	private StatisticDao statisticDao;
	public StatisticServiceImpl(StatisticDao statisticDao){
		this.statisticDao=statisticDao;
	}
	@Override
	public void increaseStudyHits(String id) throws Exception {
		statisticDao.increaseStudyHits(id);
	}
	@Override
	public void increaseFinanceHits(String id) throws Exception {
		statisticDao.increaseFinanceHits(id);
	}
	@Override
	public void increaseSportsHits(String id) throws Exception {
		statisticDao.increaseSportsHits(id);
	}
	@Override
	public void increaseLivingHits(String id) throws Exception {
		statisticDao.increaseLivingHits(id);
	}
	@Override
	public void increaseSmokingHits(String id) throws Exception {
		statisticDao.increaseSmokingHits(id);
	}
	@Override
	public GroupHitsVO selectGroupHitsById(String id) throws Exception {
		return statisticDao.selectGroupHitsById(id);
	}
	@Override
	public void insertGroupHits(GroupHitsVO groupHitsVO) throws Exception {
		statisticDao.insertGroupHits(groupHitsVO);
	}
	/**
	  * Member Point를 확인한다
	  */
	 @Override
	 public void confirmMemberPoint(MemberVO mvo) throws Exception {
	  //가장 마지막 id의 timePosted값을 받는다
	  String time = statisticDao.selectMemeberTimePostedById(mvo.getId());
	  StatisticPointVO spvo = new StatisticPointVO(mvo.getId(),mvo.getStudy_point(),mvo.getSports_point(),mvo.getSmoking_point(),mvo.getFinance_point(),mvo.getLiving_point());
	  //값이 없으면 insert
	  if(time==null){
	   //System.out.println("time null");
	   statisticDao.insertMemberPointStatistic(spvo);
	  }else{
	   //받아온 timePosted값이 하루를 지나지 않았으면 insert
	   time = statisticDao.selectMemeberTimePostedById(mvo.getId());
	   String currentTime = statisticDao.selectCurrentTime();
	   if(time.equals(currentTime)){
	    System.out.println("하루에 한 번 이상 입력이 안됨");
	   }else{
	    statisticDao.insertMemberPointStatistic(spvo);
	   }
	   //그렇지 않으면 아무것도 안함
	  }
	 }
	@Override
	public List<StatisticPointVO> selectListStatisticPoint(String id)
			throws Exception {
		return statisticDao.selectListStatisticPoint(id);
	}
}
